package lily.phs.urh;

import lily.phs.object.HealthTest;
import lily.phs.object.HereTipa;
import lily.phs.urh.R;
import lily.ui.control.MyPopupWindow;

import android.view.View.OnFocusChangeListener;
import android.content.Context;
import android.text.InputType;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;

/**
 * 健康体检表（Page 1）的界面布局和数据处理封装的view类
 * @author heckassitant
 *
 */
public class HealthTest_1 extends LinearLayout implements OnClickListener, OnFocusChangeListener{

	private MyPopupWindow mPopupWindow;
	private Context mContext;
	private int profileid = 0;//档案ID
	private int testid = 0;//体检表ID
	private EditText et_name,et_id,et_date,et_doctor,et_symptom_other,et_body_temperature,et_pulse_rate,et_respiratory_rate,
	                 et_bloodpressure_left_high,et_bloodpressure_left_low,et_bloodpressure_right_high,et_bloodpressure_right_low,
	                 et_height,et_weight,et_waistline,et_bmt,et_olds_intelligence,et_olds_depression,et_exe_per_time,et_exe_lastlong,et_exe_method,
	                 et_smoke_per_day,et_smoke_startage,et_smoke_quitage;
	
	private CheckBox cb_symptom_1,cb_symptom_2,cb_symptom_3,cb_symptom_4,cb_symptom_5,cb_symptom_6,cb_symptom_7,cb_symptom_8,
	                 cb_symptom_9,cb_symptom_10,cb_symptom_11,cb_symptom_12,cb_symptom_13,cb_symptom_14,cb_symptom_15,cb_symptom_16,
	                 cb_symptom_17,cb_symptom_18,cb_symptom_19,cb_symptom_20,cb_symptom_21,cb_symptom_22,cb_symptom_23,cb_symptom_24,cb_symptom_25,
	                 cb_diet_1,cb_diet_2,cb_diet_3,cb_diet_4,cb_diet_5,cb_diet_6;
	private RadioGroup rgOldsHealth,rgOldsCognition,rgOldsEmotion,rgExeFq,rgSmoke;
	private RadioButton rb_olds_health_1,rb_olds_health_2,rb_olds_health_3,rb_olds_health_4,rb_olds_health_5,
	                    rb_olds_selfcare_1,rb_olds_selfcare_2,rb_olds_selfcare_3,rb_olds_selfcare_4,
	                    rb_olds_cognition_1,rb_olds_cognition_2,rb_olds_emotion_1,rb_olds_emotion_2,
	                    rb_exe_fq_1,rb_exe_fq_2,rb_exe_fq_3,rb_exe_fq_4,rb_smoke_1,rb_smoke_2,rb_smoke_3;
	
	private HereTipa ht;
	private HealthTest htest;
	private View child;
	
	public HealthTest_1(Context context,int profileId,int testId) {
		super(context);
		// TODO Auto-generated constructor stub
		//档案编号
		this.profileid = profileId;
		this.testid = testId;
		this.mContext = context;
		
		//将布局生成View
		final LayoutInflater inflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		child = inflater.inflate(R.layout.healthtest_1, null);
		//LayoutParams lp = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
		//this.addView(child,lp);
		
		//findViewsById();
		
		//initViews();
		
	}

	public int getProfileid() {
		return profileid;
	}

	public void setProfileid(int profileid) {
		this.profileid = profileid;
	}

	public int getTestid() {
		return testid;
	}

	public void setTestid(int testid) {
		this.testid = testid;
	}

	public void findViewsById() {
		// TODO Auto-generated method stub
		
		et_name = (EditText)child.findViewById(R.id.ht_name);
		et_id = (EditText)child.findViewById(R.id.ht_id);
		et_date = (EditText)child.findViewById(R.id.ht1_tijian_date);
		et_date.setInputType(InputType.TYPE_NULL);//不显示虚拟键盘
		et_date.setOnClickListener(this);
		et_date.setOnFocusChangeListener(this);
		et_doctor = (EditText)child.findViewById(R.id.ht1_doctor);
		et_symptom_other = (EditText)child.findViewById(R.id.ht1_symptom_other);
		et_symptom_other.setOnFocusChangeListener(this);
		et_symptom_other.setOnClickListener(this);
		et_body_temperature = (EditText)child.findViewById(R.id.ht1_general_bodytemprature);
		et_pulse_rate = (EditText)child.findViewById(R.id.ht1_general_pulse_rate);
		et_respiratory_rate = (EditText)child.findViewById(R.id.ht1_general_respiratory_rate);
        et_bloodpressure_left_high = (EditText)child.findViewById(R.id.ht1_general_bloodpressure_left_high);
        et_bloodpressure_left_low = (EditText)child.findViewById(R.id.ht1_general_bloodpressure_left_low);
        et_bloodpressure_right_high = (EditText)child.findViewById(R.id.ht1_general_bloodpressure_right_high);
        et_bloodpressure_right_low = (EditText)child.findViewById(R.id.ht1_general_bloodpressure_right_low);
        et_height = (EditText)child.findViewById(R.id.ht1_general_height);
        et_weight = (EditText)child.findViewById(R.id.ht1_general_weight);
        et_waistline = (EditText)child.findViewById(R.id.ht1_general_waistline);
        et_bmt = (EditText)child.findViewById(R.id.ht1_general_bmt);
        et_olds_intelligence = (EditText)child.findViewById(R.id.ht1_general_olds_intelligence);
        et_olds_depression = (EditText)child.findViewById(R.id.ht1_general_olds_depression);
        et_exe_per_time = (EditText)child.findViewById(R.id.ht1_lifestyle_exe_per_time);
        et_exe_lastlong = (EditText)child.findViewById(R.id.ht1_lifestyle_exe_lastlong);
        et_exe_method = (EditText)child.findViewById(R.id.ht1_lifestyle_exe_method);
        et_smoke_per_day = (EditText)child.findViewById(R.id.ht1_lifestyle_smoke_per_day);
        et_smoke_startage = (EditText)child.findViewById(R.id.ht1_lifestyle_smoke_startage);
        et_smoke_quitage = (EditText)child.findViewById(R.id.ht1_lifestyle_smoke_quitage);
        cb_symptom_1 = (CheckBox)child.findViewById(R.id.ht1_symptom_1);
        cb_symptom_2 = (CheckBox)child.findViewById(R.id.ht1_symptom_2);
        cb_symptom_3 = (CheckBox)child.findViewById(R.id.ht1_symptom_3);
        cb_symptom_4 = (CheckBox)child.findViewById(R.id.ht1_symptom_4);
        cb_symptom_5 = (CheckBox)child.findViewById(R.id.ht1_symptom_5);
        cb_symptom_6 = (CheckBox)child.findViewById(R.id.ht1_symptom_6);
        cb_symptom_7 = (CheckBox)child.findViewById(R.id.ht1_symptom_7);
        cb_symptom_8 = (CheckBox)child.findViewById(R.id.ht1_symptom_8);
        cb_symptom_9 = (CheckBox)child.findViewById(R.id.ht1_symptom_9);
        cb_symptom_10 = (CheckBox)child.findViewById(R.id.ht1_symptom_10);
        cb_symptom_11 = (CheckBox)child.findViewById(R.id.ht1_symptom_11);
        cb_symptom_12 = (CheckBox)child.findViewById(R.id.ht1_symptom_12);
        cb_symptom_13 = (CheckBox)child.findViewById(R.id.ht1_symptom_13);
        cb_symptom_14 = (CheckBox)child.findViewById(R.id.ht1_symptom_14);
        cb_symptom_15 = (CheckBox)child.findViewById(R.id.ht1_symptom_15);
        cb_symptom_16 = (CheckBox)child.findViewById(R.id.ht1_symptom_16);
        cb_symptom_17 = (CheckBox)child.findViewById(R.id.ht1_symptom_17);
        cb_symptom_18 = (CheckBox)child.findViewById(R.id.ht1_symptom_18);
        cb_symptom_19 = (CheckBox)child.findViewById(R.id.ht1_symptom_19);
        cb_symptom_20 = (CheckBox)child.findViewById(R.id.ht1_symptom_20);
        cb_symptom_21 = (CheckBox)child.findViewById(R.id.ht1_symptom_21);
        cb_symptom_22 = (CheckBox)child.findViewById(R.id.ht1_symptom_22);
        cb_symptom_23 = (CheckBox)child.findViewById(R.id.ht1_symptom_23);
        cb_symptom_24 = (CheckBox)child.findViewById(R.id.ht1_symptom_24);
        cb_symptom_25 = (CheckBox)child.findViewById(R.id.ht1_symptom_25);
        cb_diet_1 = (CheckBox)child.findViewById(R.id.ht1_lifestyle_diet_1);
        cb_diet_2 = (CheckBox)child.findViewById(R.id.ht1_lifestyle_diet_2);
        cb_diet_3 = (CheckBox)child.findViewById(R.id.ht1_lifestyle_diet_3);
        cb_diet_4 = (CheckBox)child.findViewById(R.id.ht1_lifestyle_diet_4);
        cb_diet_5 = (CheckBox)child.findViewById(R.id.ht1_lifestyle_diet_5);
        cb_diet_6 = (CheckBox)child.findViewById(R.id.ht1_lifestyle_diet_6);
        rb_olds_health_1 = (RadioButton)child.findViewById(R.id.ht1_general_olds_health_1);
        rb_olds_health_2 = (RadioButton)child.findViewById(R.id.ht1_general_olds_health_2);
        rb_olds_health_3 = (RadioButton)child.findViewById(R.id.ht1_general_olds_health_3);
        rb_olds_health_4 = (RadioButton)child.findViewById(R.id.ht1_general_olds_health_4);
        rb_olds_health_5 = (RadioButton)child.findViewById(R.id.ht1_general_olds_health_5);
        rb_olds_selfcare_1 = (RadioButton)child.findViewById(R.id.ht1_general_olds_selfcare_1);
        rb_olds_selfcare_1.setOnClickListener(this);
        rb_olds_selfcare_2 = (RadioButton)child.findViewById(R.id.ht1_general_olds_selfcare_2);
        rb_olds_selfcare_2.setOnClickListener(this);
        rb_olds_selfcare_3 = (RadioButton)child.findViewById(R.id.ht1_general_olds_selfcare_3);
        rb_olds_selfcare_3.setOnClickListener(this);
        rb_olds_selfcare_4 = (RadioButton)child.findViewById(R.id.ht1_general_olds_selfcare_4);
        rb_olds_selfcare_4.setOnClickListener(this);
        rb_olds_cognition_1 = (RadioButton)child.findViewById(R.id.ht1_general_olds_cognition_1);
        rb_olds_cognition_2 = (RadioButton)child.findViewById(R.id.ht1_general_olds_cognition_2);
        rb_olds_emotion_1 = (RadioButton)child.findViewById(R.id.ht1_general_olds_emotion_1);
        rb_olds_emotion_2 = (RadioButton)child.findViewById(R.id.ht1_general_olds_emotion_2);
        rb_exe_fq_1 = (RadioButton)child.findViewById(R.id.ht1_lifestyle_exe_fq_1);
        rb_exe_fq_2 = (RadioButton)child.findViewById(R.id.ht1_lifestyle_exe_fq_2);
        rb_exe_fq_3 = (RadioButton)child.findViewById(R.id.ht1_lifestyle_exe_fq_3);
        rb_exe_fq_4 = (RadioButton)child.findViewById(R.id.ht1_lifestyle_exe_fq_4);
        rb_smoke_1 = (RadioButton)child.findViewById(R.id.ht1_lifestyle_smoke_1);
        rb_smoke_2 = (RadioButton)child.findViewById(R.id.ht1_lifestyle_smoke_2);
        rb_smoke_3 = (RadioButton)child.findViewById(R.id.ht1_lifestyle_smoke_3);
        rgOldsHealth = (RadioGroup)child.findViewById(R.id.radiogroup_test);
        rgOldsCognition = (RadioGroup)child.findViewById(R.id.radioGroup1);
        rgOldsEmotion = (RadioGroup)child.findViewById(R.id.RadioGroup01);
        rgExeFq = (RadioGroup)child.findViewById(R.id.exefq);
        rgSmoke = (RadioGroup)child.findViewById(R.id.smoke);
	}

	/**
	 * 填充views
	 */
	public void initViews() {
		// TODO Auto-generated method stub
		
		initialState();
        
		System.out.println("initviews="+htest.getHete_testid());
		if(ht.getHeti_name()!=null){
			et_name.setText(ht.getHeti_name());
		}
		if(ht.getHeti_here_id()!=null){
			et_id.setText(ht.getHeti_here_id());
		}
		et_name.setEnabled(false);
		et_id.setEnabled(false);
		
		//填充体检表page1
		String temp = "";
		int itemp = -1;
		float ftemp = -1f;
		
		temp = htest.getHete_date();
		if(temp.length()>0){
			et_date.setText(temp);
		}
		
		temp = htest.getHete_doctor();
		if(temp.length()>0){
			et_doctor.setText(temp);
		}
		
		temp = htest.getHete_symptom();
		if(temp.length()>0){
			String[] ss = temp.split(",");
			for(int i=0;i<ss.length;i++){
				int k = Integer.parseInt(ss[i]);
				switch(k){
				case 1:
					cb_symptom_1.setChecked(true);
					break;
				case 2:
					cb_symptom_2.setChecked(true);
					break;
				case 3:
					cb_symptom_3.setChecked(true);
					break;
				case 4:
					cb_symptom_4.setChecked(true);
					break;
				case 5:
					cb_symptom_5.setChecked(true);
					break;
				case 6:
					cb_symptom_6.setChecked(true);
					break;
				case 7:
					cb_symptom_7.setChecked(true);
					break;
				case 8:
					cb_symptom_8.setChecked(true);
					break;
				case 9:
					cb_symptom_9.setChecked(true);
					break;
				case 10:
					cb_symptom_10.setChecked(true);
					break;
				case 11:
					cb_symptom_11.setChecked(true);
					break;
				case 12:
					cb_symptom_12.setChecked(true);
					break;
				case 13:
					cb_symptom_13.setChecked(true);
					break;
				case 14:
					cb_symptom_14.setChecked(true);
					break;
				case 15:
					cb_symptom_15.setChecked(true);
					break;
				case 16:
					cb_symptom_16.setChecked(true);
					break;
				case 17:
					cb_symptom_17.setChecked(true);
					break;
				case 18:
					cb_symptom_18.setChecked(true);
					break;
				case 19:
					cb_symptom_19.setChecked(true);
					break;
				case 20:
					cb_symptom_20.setChecked(true);
					break;
				case 21:
					cb_symptom_21.setChecked(true);
					break;
				case 22:
					cb_symptom_22.setChecked(true);
					break;
				case 23:
					cb_symptom_23.setChecked(true);
					break;
				case 24:
					cb_symptom_24.setChecked(true);
					break;
				case 25:{
					cb_symptom_25.setChecked(true);
					temp = htest.getHete_symptom_other();
					et_symptom_other.setText(temp);
					break;
				}
				}
			}
		}
		
		ftemp = htest.getHete_body_temperature();
		if(ftemp!=-1f){
			et_body_temperature.setText(String.valueOf(ftemp));			
		}
		
		itemp = htest.getHete_pulse_rate();
		if(itemp!=-1){
			et_pulse_rate.setText(String.valueOf(itemp));			
		}
		
		itemp = htest.getHete_respiratory_rate();
		if(itemp!=-1){
			et_respiratory_rate.setText(String.valueOf(itemp));
		}
		
		itemp = htest.getHete_bloodpressure_left_high();
		if(itemp!=-1){
			et_bloodpressure_left_high.setText(String.valueOf(itemp));
		}
		itemp = htest.getHete_bloodpressure_left_low();
		if(itemp!=-1){
			et_bloodpressure_left_low.setText(String.valueOf(itemp));
		}
		itemp = htest.getHete_bloodpressure_right_high();
		if(itemp!=-1){
			et_bloodpressure_right_high.setText(String.valueOf(itemp));
		}
		itemp = htest.getHete_bloodpressure_right_low();
		if(itemp!=-1){
			et_bloodpressure_right_low.setText(String.valueOf(itemp));
		}
		
		itemp = htest.getHete_height();
		if(itemp!=-1){
			et_height.setText(String.valueOf(itemp));
		}
		ftemp = htest.getHete_weight();
		if(ftemp!=-1f){
			et_weight.setText(String.valueOf(ftemp));			
		}
		itemp = htest.getHete_waistline();
		if(itemp!=-1){
			et_waistline.setText(String.valueOf(itemp));
		}
		ftemp = htest.getHete_bmt();
		if(ftemp!=-1f){
			et_bmt.setText(String.valueOf(ftemp));			
		}
		
		itemp = htest.getHete_olds_health();
		switch(itemp){
		case 1:
			rgOldsHealth.check(0);
			rb_olds_health_1.setChecked(true);
			break;
		case 2:
			rgOldsHealth.check(1);
			rb_olds_health_2.setChecked(true);
			break;
		case 3:
			rgOldsHealth.check(2);
			rb_olds_health_3.setChecked(true);
			break;
		case 4:
			rgOldsHealth.check(3);
			rb_olds_health_4.setChecked(true);
			break;
		case 5:
			rgOldsHealth.check(4);
			rb_olds_health_5.setChecked(true);
			break;
		}
		
		itemp = htest.getHete_olds_selfcare();
		switch(itemp){
		case 1:
			rb_olds_selfcare_1.setChecked(true);
			break;
		case 2:
			rb_olds_selfcare_2.setChecked(true);
			break;
		case 3:
			rb_olds_selfcare_3.setChecked(true);
			break;
		case 4:
			rb_olds_selfcare_4.setChecked(true);
			break;
		}
		
		itemp = htest.getHete_olds_cognition();
		switch(itemp){
		case 1:
			rgOldsCognition.check(0);
			rb_olds_cognition_1.setChecked(true);
			break;
		case 2:
			rgOldsCognition.check(1);
			rb_olds_cognition_2.setChecked(true);
			break;
		}
		
		itemp = htest.getHete_olds_emotion();
		switch(itemp){
		case 1:
			rgOldsEmotion.check(0);
			rb_olds_emotion_1.setChecked(true);
			break;
		case 2:
			rgOldsEmotion.check(1);
			rb_olds_emotion_2.setChecked(true);
			break;
		}
		
		itemp = htest.getHete_olds_intelligence();
		if(itemp!=-1){
			et_olds_intelligence.setText(String.valueOf(itemp));
		}
		itemp = htest.getHete_olds_depression();
		if(itemp!=-1){
			et_olds_depression.setText(String.valueOf(itemp));
		}
		
		itemp = htest.getHete_exercise_fq();
		switch(itemp){
		case 1:
			rgExeFq.check(0);
			rb_exe_fq_1.setChecked(true);
			break;
		case 2:
			rgExeFq.check(1);
			rb_exe_fq_2.setChecked(true);
			break;
		case 3:
			rgExeFq.check(2);
			rb_exe_fq_3.setChecked(true);
			break;
		case 4:
			rgExeFq.check(3);
			rb_exe_fq_4.setChecked(true);
			break;
		}
		
		itemp = htest.getHete_exercise_per_time();
		if(itemp!=-1){
			et_exe_per_time.setText(String.valueOf(itemp));
		}
		itemp = htest.getHete_exercise_lastlong();
		if(itemp!=-1){
			et_exe_lastlong.setText(String.valueOf(itemp));
		}
		temp = htest.getHete_exercise_method();
		if(temp.length()>0){
			et_exe_method.setText(temp);
		}
		
		temp = htest.getHete_diet_habit();
		if(temp.length()>0){
			String[] ss = temp.split(",");
			for(int i=0;i<ss.length;i++){
				int k = Integer.parseInt(ss[i]);
				switch(k){
				case 1:
					cb_diet_1.setChecked(true);
					break;
				case 2:
					cb_diet_2.setChecked(true);
					break;
				case 3:
					cb_diet_3.setChecked(true);
					break;
				case 4:
					cb_diet_4.setChecked(true);
					break;
				case 5:
					cb_diet_5.setChecked(true);
					break;
				case 6:
					cb_diet_6.setChecked(true);
					break;
				}
			}
		}
		
		itemp = htest.getHete_smoke();
		switch(itemp){
		case 1:
			rgSmoke.check(0);
			rb_smoke_1.setChecked(true);
			break;
		case 2:
			rgSmoke.check(1);
			rb_smoke_2.setChecked(true);
			break;
		case 3:
			rgSmoke.check(2);
			rb_smoke_3.setChecked(true);
			break;
		}
		
		itemp = htest.getHete_smoke_per_day();
		if(itemp!=-1){
			et_smoke_per_day.setText(String.valueOf(itemp));
		}
		itemp = htest.getHete_smoke_startage();
		if(itemp!=-1){
			et_smoke_startage.setText(String.valueOf(itemp));
		}
		itemp = htest.getHete_smoke_quitage();
		if(itemp!=-1){
			et_smoke_quitage.setText(String.valueOf(itemp));
		}
		
		
	}

	/**
	 * 初始时显示空表：横线为空，所有选择项未选中
	 */
	private void initialState() {
		// TODO Auto-generated method stub
        et_name.setText("");
        et_id.setText("");
        et_date.setText("");
        et_doctor.setText("");
        et_symptom_other.setText("");
        et_body_temperature.setText("");
        et_pulse_rate.setText("");
        et_respiratory_rate.setText("");
        et_bloodpressure_left_high.setText("");
        et_bloodpressure_left_low.setText("");
        et_bloodpressure_right_high.setText("");
        et_bloodpressure_right_low.setText("");
        et_height.setText("");
        et_weight.setText("");
        et_waistline.setText("");
        et_bmt.setText("");
        et_olds_intelligence.setText("");
        et_olds_depression.setText("");
        et_exe_per_time.setText("");
        et_exe_lastlong.setText("");
        et_exe_method.setText("");
        et_smoke_per_day.setText("");
        et_smoke_startage.setText("");
        et_smoke_quitage.setText("");
        cb_symptom_1.setChecked(false);
        cb_symptom_2.setChecked(false);
        cb_symptom_3.setChecked(false);
        cb_symptom_4.setChecked(false);
        cb_symptom_5.setChecked(false);
        cb_symptom_6.setChecked(false);
        cb_symptom_7.setChecked(false);
        cb_symptom_8.setChecked(false);
        cb_symptom_9.setChecked(false);
        cb_symptom_10.setChecked(false);
        cb_symptom_11.setChecked(false);
        cb_symptom_12.setChecked(false);
        cb_symptom_13.setChecked(false);
        cb_symptom_14.setChecked(false);
        cb_symptom_15.setChecked(false);
        cb_symptom_16.setChecked(false);
        cb_symptom_17.setChecked(false);
        cb_symptom_18.setChecked(false);
        cb_symptom_19.setChecked(false);
        cb_symptom_20.setChecked(false);
        cb_symptom_21.setChecked(false);
        cb_symptom_22.setChecked(false);
        cb_symptom_23.setChecked(false);
        cb_symptom_24.setChecked(false);
        cb_symptom_25.setChecked(false);
        cb_diet_1.setChecked(false);
        cb_diet_2.setChecked(false);
        cb_diet_3.setChecked(false);
        cb_diet_4.setChecked(false);
        cb_diet_5.setChecked(false);
        cb_diet_6.setChecked(false);
        rb_olds_health_1.setChecked(false);
        rb_olds_health_2.setChecked(false);
        rb_olds_health_3.setChecked(false);
        rb_olds_health_4.setChecked(false);
        rb_olds_health_5.setChecked(false);
        rb_olds_selfcare_1.setChecked(false);
        rb_olds_selfcare_2.setChecked(false);
        rb_olds_selfcare_3.setChecked(false);
        rb_olds_selfcare_4.setChecked(false);
        rb_olds_cognition_1.setChecked(false);
        rb_olds_cognition_2.setChecked(false);
        rb_olds_emotion_1.setChecked(false);
        rb_olds_emotion_2.setChecked(false);
        rb_exe_fq_1.setChecked(false);
        rb_exe_fq_2.setChecked(false);
        rb_exe_fq_3.setChecked(false);
        rb_exe_fq_4.setChecked(false);
        rb_smoke_1.setChecked(false);
        rb_smoke_2.setChecked(false);
        rb_smoke_3.setChecked(false);
		
	}

	/**
	 * 添加view到contentview
	 */
	public void setMyView(){
		this.removeAllViews();
		LayoutParams lp = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
		this.addView(child,lp);
//		System.out.println("setMyView="+htest.getHete_testid());
	}
	
	/**
	 * 将整个界面作为一个view对象
	 * @return 整个界面view
	 */
	public View getMyView(){
		return this.child;
	}
	
	/**
	 * 检查数据
	 */
	public void fetchData(){
        ht=new HereTipa(mContext);//从封面表中检出姓名和编号,姓名和编号不可更改
		ht.selectNameAndCode(this.profileid);
		htest = new HealthTest(mContext);
		htest.selectHealthTest(this.profileid,this.testid);
		System.out.println("htest.fetchData="+htest.getHete_testid());
	}
	
	
	/**
	 * 读取views的值并保存至ID对应的记录中
	 */
	public void saveViews() {
		// TODO Auto-generated method stub
		HealthTest htest = new HealthTest(mContext);
		htest.selectHealthTest(profileid, testid);
		String temp = "";
		StringBuffer sb = new StringBuffer();
//		int itemp = -1;
//		float ftemp = -1.0f;
		
		temp = et_date.getText().toString();
		htest.setHete_date(temp);
		temp = et_doctor.getText().toString();
		htest.setHete_doctor(temp);
		
		if(cb_symptom_1.isChecked()==true){
			sb.append("1,");
		}
		if(cb_symptom_2.isChecked()==true){
			sb.append("2,");
		}
		if(cb_symptom_3.isChecked()==true){
			sb.append("3,");
		}
		if(cb_symptom_4.isChecked()==true){
			sb.append("4,");
		}
		if(cb_symptom_5.isChecked()==true){
			sb.append("5,");
		}
		if(cb_symptom_6.isChecked()==true){
			sb.append("6,");
		}
		if(cb_symptom_7.isChecked()==true){
			sb.append("7,");
		}
		if(cb_symptom_8.isChecked()==true){
			sb.append("8,");
		}
		if(cb_symptom_9.isChecked()==true){
			sb.append("9,");
		}
		if(cb_symptom_10.isChecked()==true){
			sb.append("10,");
		}
		if(cb_symptom_11.isChecked()==true){
			sb.append("11,");
		}
		if(cb_symptom_12.isChecked()==true){
			sb.append("12,");
		}
		if(cb_symptom_13.isChecked()==true){
			sb.append("13,");
		}
		if(cb_symptom_14.isChecked()==true){
			sb.append("14,");
		}
		if(cb_symptom_15.isChecked()==true){
			sb.append("15,");
		}
		if(cb_symptom_16.isChecked()==true){
			sb.append("16,");
		}
		if(cb_symptom_17.isChecked()==true){
			sb.append("17,");
		}
		if(cb_symptom_18.isChecked()==true){
			sb.append("18,");
		}
		if(cb_symptom_19.isChecked()==true){
			sb.append("19,");
		}
		if(cb_symptom_20.isChecked()==true){
			sb.append("20,");
		}
		if(cb_symptom_21.isChecked()==true){
			sb.append("21,");
		}
		if(cb_symptom_22.isChecked()==true){
			sb.append("22,");
		}
		if(cb_symptom_23.isChecked()==true){
			sb.append("23,");
		}
		if(cb_symptom_24.isChecked()==true){
			sb.append("24,");
		}
		if(cb_symptom_25.isChecked()==true){
			sb.append("25,");
			temp = et_symptom_other.getText().toString();
			htest.setHete_symptom_other(temp);
		}
		htest.setHete_symptom(sb.toString());
		
		temp = et_body_temperature.getText().toString();
		if(temp.length()>0){
			htest.setHete_body_temperature(Float.parseFloat(temp));
		}
		
		temp = et_pulse_rate.getText().toString();
		if(temp.length()>0){
			htest.setHete_pulse_rate( Integer.parseInt(temp));
		}
		temp = et_respiratory_rate.getText().toString();
		if(temp.length()>0){
			htest.setHete_respiratory_rate(Integer.parseInt(temp));
		}
		temp = et_bloodpressure_left_high.getText().toString();
		if(temp.length()>0){
			htest.setHete_bloodpressure_left_high(Integer.parseInt(temp));
		}
		temp = et_bloodpressure_left_low.getText().toString();
		if(temp.length()>0){
			htest.setHete_bloodpressure_left_low(Integer.parseInt(temp));
		}
		temp = et_bloodpressure_right_high.getText().toString();
		if(temp.length()>0){
			htest.setHete_bloodpressure_right_high(Integer.parseInt(temp));
		}
		temp = et_bloodpressure_right_low.getText().toString();
		if(temp.length()>0){
			htest.setHete_bloodpressure_right_low(Integer.parseInt(temp));
		}
		temp = et_height.getText().toString();
		if(temp.length()>0){
			htest.setHete_height(Integer.parseInt(temp));
		}
		temp = et_weight.getText().toString();
		if(temp.length()>0){
			htest.setHete_weight(Float.parseFloat(temp));
		}
		temp = et_waistline.getText().toString();
		if(temp.length()>0){
			htest.setHete_waistline(Integer.parseInt(temp));
		}
		temp = et_bmt.getText().toString();
		if(temp.length()>0){
			htest.setHete_bmt(Float.parseFloat(temp));
		}
		
		if(rb_olds_health_1.isChecked()==true){
			htest.setHete_olds_health(1);
		}else if(rb_olds_health_2.isChecked()==true){
			htest.setHete_olds_health(2);
		}else if(rb_olds_health_3.isChecked()==true){
			htest.setHete_olds_health(3);
		}else if(rb_olds_health_4.isChecked()==true){
			htest.setHete_olds_health(4);
		}else if(rb_olds_health_5.isChecked()==true){
			htest.setHete_olds_health(5);
		}
		
		if(rb_olds_selfcare_1.isChecked()==true){
			htest.setHete_olds_selfcare(1);
		}else if(rb_olds_selfcare_2.isChecked()==true){
			htest.setHete_olds_selfcare(2);
		}else if(rb_olds_selfcare_3.isChecked()==true){
			htest.setHete_olds_selfcare(3);
		}else if(rb_olds_selfcare_4.isChecked()==true){
			htest.setHete_olds_selfcare(4);
		} 
		
		if(rb_olds_cognition_1.isChecked()==true){
			htest.setHete_olds_cognition(1);
		}else if(rb_olds_cognition_2.isChecked()==true){
			htest.setHete_olds_cognition(2);
		}
		temp = et_olds_intelligence.getText().toString();
		if(temp.length()>0){
			htest.setHete_olds_intelligence(Integer.parseInt(temp));
		}
		temp = et_olds_depression.getText().toString();
		if(temp.length()>0){
			htest.setHete_olds_depression(Integer.parseInt(temp));
		}
		if(rb_olds_emotion_1.isChecked()==true){
			htest.setHete_olds_emotion(1);
		}else if(rb_olds_emotion_2.isChecked()==true){
			htest.setHete_olds_emotion(2);
		}
		
		if(rb_exe_fq_1.isChecked()==true){
			htest.setHete_exercise_fq(1);
		}else if(rb_exe_fq_2.isChecked()==true){
			htest.setHete_exercise_fq(2);
		}else if(rb_exe_fq_3.isChecked()==true){
			htest.setHete_exercise_fq(3);
		}else if(rb_exe_fq_4.isChecked()==true){
			htest.setHete_exercise_fq(4);
		}
		
		temp =et_exe_per_time.getText().toString();
		if(temp.length()>0){
			htest.setHete_exercise_per_time( Integer.parseInt(temp));
		}
		temp = et_exe_lastlong.getText().toString();
		if(temp.length()>0){
			htest.setHete_exercise_lastlong(Integer.parseInt(temp));
		}
		temp = et_exe_method.getText().toString();
		htest.setHete_exercise_method(temp);
		
		sb = new StringBuffer();
		if(cb_diet_1.isChecked()==true){
			sb.append("1,");
		}
		if(cb_diet_2.isChecked()==true){
			sb.append("2,");
		}
		if(cb_diet_3.isChecked()==true){
			sb.append("3,");
		}
		if(cb_diet_4.isChecked()==true){
			sb.append("4,");
		}
		if(cb_diet_5.isChecked()==true){
			sb.append("5,");
		}
		if(cb_diet_6.isChecked()==true){
			sb.append("6,");
		}
		htest.setHete_diet_habit(sb.toString());
		
		if(rb_smoke_1.isChecked()==true){
			htest.setHete_smoke(1);
		}else if(rb_smoke_2.isChecked()==true){
			htest.setHete_smoke(2);
		}else if(rb_smoke_3.isChecked()==true){
			htest.setHete_smoke(3);
		}
		
		temp = et_smoke_per_day.getText().toString();
		if(temp.length()>0){
			htest.setHete_smoke_per_day(Integer.parseInt(temp));
		}
		temp = et_smoke_startage.getText().toString();
		if(temp.length()>0){
			htest.setHete_smoke_startage(Integer.parseInt(temp));
		}
		temp = et_smoke_quitage.getText().toString();
		if(temp.length()>0){
			htest.setHete_smoke_quitage(Integer.parseInt(temp));
		}
		
		htest.updateHealthTest(this.profileid,this.testid);
		
	}

	@Override
	
	public void onFocusChange(View v, boolean hasFocus) {
		// TODO Auto-generated method stub
		if(v==et_date&&hasFocus){
			mPopupWindow = new MyPopupWindow(getContext());			
			mPopupWindow.showAtLocation(findViewById(R.id.ht1_tijian_date), Gravity.CENTER, 0, 0);

			Button btn=mPopupWindow.getButton();
			btn.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					et_date.setText(mPopupWindow.getDate());
					mPopupWindow.dismiss();
				}
				
			});
		}
    }
	
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if(v==et_date){
			mPopupWindow = new MyPopupWindow(mContext);			
			mPopupWindow.showAtLocation(v.findViewById(R.id.ht1_tijian_date), Gravity.CENTER, 0, 0);

			Button btn=mPopupWindow.getButton();
			btn.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					et_date.setText(mPopupWindow.getDate());
					mPopupWindow.dismiss();
				}
				
			});
		}
		else if(v==rb_olds_selfcare_1){
			rb_olds_selfcare_1.setChecked(true);
			rb_olds_selfcare_2.setChecked(false);
			rb_olds_selfcare_3.setChecked(false);
			rb_olds_selfcare_4.setChecked(false);
		}
		else if(v==rb_olds_selfcare_2){
			rb_olds_selfcare_1.setChecked(false);
			rb_olds_selfcare_2.setChecked(true);
			rb_olds_selfcare_3.setChecked(false);
			rb_olds_selfcare_4.setChecked(false);
		}
		else if(v==rb_olds_selfcare_3){
			rb_olds_selfcare_1.setChecked(false);
			rb_olds_selfcare_2.setChecked(false);
			rb_olds_selfcare_3.setChecked(true);
			rb_olds_selfcare_4.setChecked(false);
		}
		else if(v==rb_olds_selfcare_4){
			rb_olds_selfcare_1.setChecked(false);
			rb_olds_selfcare_2.setChecked(false);
			rb_olds_selfcare_3.setChecked(false);
			rb_olds_selfcare_4.setChecked(true);
		}
		else if(v==et_symptom_other){
			cb_symptom_25.setChecked(true);
		}
		
	}

	

}
